using FreeSql.DataAnnotations;

namespace SumerCoreDevOps.Domain.Entities;

/// <summary>
/// 镜像标签规则实体
/// </summary>
[Table(Name = "image_tag_rules")]
public class ImageTagRule
{
    /// <summary>
    /// 规则 ID
    /// </summary>
    [Column(IsPrimary = true, IsIdentity = true)]
    public long Id { get; set; }

    /// <summary>
    /// 关联的工作流 ID
    /// </summary>
    [Column(IsNullable = false)]
    public long WorkflowId { get; set; }

    /// <summary>
    /// 规则名称
    /// </summary>
    [Column(StringLength = 200, IsNullable = false)]
    public string Name { get; set; } = null!;

    /// <summary>
    /// 镜像仓库地址
    /// 例如：harbor.example.com、registry.hub.docker.com
    /// </summary>
    [Column(StringLength = 500, IsNullable = false)]
    public string RegistryUrl { get; set; } = null!;

    /// <summary>
    /// 项目名称/命名空间
    /// 例如：auth-service、company/backend
    /// </summary>
    [Column(StringLength = 200, IsNullable = false)]
    public string ProjectName { get; set; } = null!;

    /// <summary>
    /// 标签模板
    /// 支持变量：{git-tag}、{lang}、{commit-sha8}、{env}、{build-number}、{timestamp}
    /// 例如：{git-tag}-{lang}-{commit-sha8}
    /// </summary>
    [Column(StringLength = 500, IsNullable = false)]
    public string TagTemplate { get; set; } = null!;

    /// <summary>
    /// 默认语言标识（用于模板变量）
    /// 例如：dotnet、java、nodejs
    /// </summary>
    [Column(StringLength = 50)]
    public string? DefaultLanguage { get; set; }

    /// <summary>
    /// 环境标识（用于模板变量）
    /// 例如：prod、test、dev
    /// </summary>
    [Column(StringLength = 50)]
    public string? Environment { get; set; }

    /// <summary>
    /// 是否为默认规则
    /// </summary>
    [Column(IsNullable = false)]
    public bool IsDefault { get; set; } = false;

    /// <summary>
    /// 是否启用
    /// </summary>
    [Column(IsNullable = false)]
    public bool IsEnabled { get; set; } = true;

    /// <summary>
    /// 创建时间
    /// </summary>
    [Column(IsNullable = false)]
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// 创建者
    /// </summary>
    [Column(StringLength = 100)]
    public string? CreatedBy { get; set; }

    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime? UpdatedAt { get; set; }

    /// <summary>
    /// 关联的工作流定义
    /// </summary>
    [Navigate(nameof(WorkflowId))]
    public WorkflowDefinition? Workflow { get; set; }
}
